package org.biloxi.commands.movecard;

import org.biloxi.commands.CommandRepository;
import org.biloxi.commands.impl.CommandImpl;
import org.biloxi.model.magicobjects.MagicObject;
import org.biloxi.model.mutable.GameStateMutable;
import org.biloxi.model.player.Zone;

/**
 * Move a card from one zone to another.
 * 
 * @author Peter.WM.Wong@gmail.com
 * 
 */
public class MoveCard extends CommandImpl<MoveCard.Options, MoveCard.Result> {
		
	static public class Options {
		public final Zone source;
		public final Zone dest;
		public final MagicObject card;
		public Options(Zone source, Zone dest, MagicObject card) {
			this.source = source;
			this.dest = dest;
			this.card = card;
		}
	}
	
	static public class Result{
		public final Zone source;
		public final Zone dest;
		public final MagicObject card;
		public Result(Zone source, Zone dest, MagicObject card) {
			this.source = source;
			this.dest = dest;
			this.card = card;
		}
	}
	

	public MoveCard(CommandRepository cr) {
		super(cr);
	}

	@Override
	protected Result executeImpl(Options o, GameStateMutable gameState) {
		gameState.getMutableZone(o.source).mutableMagicObjects().remove(o.card);
		o.card.setControllerID(o.dest.getOwnerid());
		gameState.getMutableZone(o.dest).mutableMagicObjects().add(o.card);
		
		return new Result(o.source, o.dest, o.card);
	}

};
